package main

import "fmt"

/**
给定一个正整数 n，生成一个包含 1 到 n2 所有元素，且元素按顺时针顺序螺旋排列的正方形矩阵。

示例:

输入: 3
输出:
[
 [ 1, 2, 3 ],
 [ 8, 9, 4 ],
 [ 7, 6, 5 ]
]

链接：https://leetcode-cn.com/problems/spiral-matrix-ii

分析:
	螺旋矩阵遍历 联动54题
	![](http://cdn.bsummer.cn/20191103142104.png)

	https://www.youtube.com/watch?v=dfGhf-Ko0L4
*/

func main() {
	a := [][]int{
		[]int{1, 2, 3},
		[]int{4, 5, 6},
		[]int{7, 8, 9},
	}
	fmt.Println(len(a))

	generateMatrix(3)
}

func generateMatrix(n int) [][]int {
	if n == 0 {
		return [][]int{}
	}

	s := 1
	ret := [][]int{}
	for i := 0; i < n; i++ {
		ret = append(ret, make([]int, n))
	}

	left := 0
	right := n - 1
	top := 0
	bottom := n - 1
	for left < right && top < bottom {
		for i := left; i < right; i++ {
			ret[top][i] = s
			s++
		}

		for i := top; i < bottom; i++ {
			ret[i][right] = s
			s++
		}

		for i := right; i > left; i-- {
			ret[bottom][i] = s
			s++
		}

		for i := bottom; i > top; i-- {
			ret[i][left] = s
			s++
		}

		left++
		right--
		top++
		bottom--
	}

	if left == right {
		ret[left][left] = s
		s++
	}

	return ret
}

func generateMatrix(n int) [][]int {

}
